package com.wty.basic.collection;

/**
 * @Author wangtengyu
 * @Create 2018-08-08-14:44
 */
public class Student implements Comparable<Student> {
    private String name;
    private int score;
    private int age;


    public Student() {
    }

    public Student(String name, int score, int age) {
        this.name = name;
        this.score = score;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", age=" + age +
                '}';
    }

    @Override
    //this是现在往集合中添加的元素，它和其他所有元素进行比较
    public int compareTo(Student stu) {
        if(this.score>stu.score){//大于配上返回1 这就是正序  等价于小于返回-1                  小于返回1与大于返回-1就是倒序
            return 1;
        }else if(this.score<stu.score){
            return -1;
        }else{
            if(this.age>stu.age){
                return 1;
            }else if(this.age<stu.age){
                return -1;
            }else{
                return 0;
            }
        }
    }
}
